package com.talkweb.historylib.dialog;

import com.talkweb.historylib.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.window.dialog.PopupDialog;
import ohos.app.Context;

/**
 * @author SUQI
 * @date 2021/2/4
 * @description 搜索弹窗
 **/
public class SelectSearchTypeDialog extends PopupDialog {

    private Component mComponent;
    private OnDialogItemClickedListener onDialogItemClicked;

    public SelectSearchTypeDialog(Context context, Component component, OnDialogItemClickedListener onDialogItemClicked) {
        super(context, component);
        this.onDialogItemClicked = onDialogItemClicked;
        initView(context);
    }

    private void initView(Context context) {
        setSize(ComponentContainer.LayoutConfig.MATCH_CONTENT, ComponentContainer.LayoutConfig.MATCH_CONTENT);
        setCornerRadius(0);
        mComponent = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_dialog_select_search_type, null, false);
        setCustomComponent(mComponent);
        setAutoClosable(true);
        Text tvTimeSearch = (Text) mComponent.findComponentById(ResourceTable.Id_tv_time_search);
        Text tvNameSearch = (Text) mComponent.findComponentById(ResourceTable.Id_tv_name_search);
        tvTimeSearch.setClickedListener(component1 -> {
            hide();
            if (onDialogItemClicked != null) {
                onDialogItemClicked.onSearchTime();
            }
        });
        tvNameSearch.setClickedListener(component1 -> {
            hide();
            if (onDialogItemClicked != null) {
                onDialogItemClicked.onSearchName();
            }
        });
    }

    public interface OnDialogItemClickedListener {
        void onSearchName();

        void onSearchTime();
    }
}
